Renamed from create_shortcuts_model(). (struct _GtkFileChooserDefault):
authorFederico Mena Quintero <federico@ximian.com>
Wed, 25 Feb 2004 03:03:11 +0000 (03:03 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Wed, 25 Feb 2004 03:03:11 +0000 (03:03 +0000)
2004-02-24  Federico Mena Quintero  <federico@ximian.com>

* gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
from create_shortcuts_model().
(struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
to shortcuts_list.
(shortcuts_list_create): Renamed from shortcuts_tree_create().
(create_file_list): Enable the tree view as a model drag source.
(create_folder_tree): Likewise.

* gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
Register the drag source interface.
(drag_source_iface_init): New function.
(drag_source_row_draggable): New function.
(drag_source_drag_data_get): New function.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdefault.c
gtk/gtkfilesystemmodel.c

index 1a13b2af34f9a290aab7bce925cba9e58cf932ad..13882efe842b98042ae9de657ab7e2dd788c3b16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2004-02-24  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+       from create_shortcuts_model().
+       (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+       to shortcuts_list.
+       (shortcuts_list_create): Renamed from shortcuts_tree_create().
+       (create_file_list): Enable the tree view as a model drag source.
+       (create_folder_tree): Likewise.
+
+       * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+       Register the drag source interface.
+       (drag_source_iface_init): New function.
+       (drag_source_row_draggable): New function.
+       (drag_source_drag_data_get): New function.
+
 Tue Feb 24 19:12:07 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.4 ===
index 1a13b2af34f9a290aab7bce925cba9e58cf932ad..13882efe842b98042ae9de657ab7e2dd788c3b16 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-24  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+       from create_shortcuts_model().
+       (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+       to shortcuts_list.
+       (shortcuts_list_create): Renamed from shortcuts_tree_create().
+       (create_file_list): Enable the tree view as a model drag source.
+       (create_folder_tree): Likewise.
+
+       * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+       Register the drag source interface.
+       (drag_source_iface_init): New function.
+       (drag_source_row_draggable): New function.
+       (drag_source_drag_data_get): New function.
+
 Tue Feb 24 19:12:07 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.4 ===
index 1a13b2af34f9a290aab7bce925cba9e58cf932ad..13882efe842b98042ae9de657ab7e2dd788c3b16 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-24  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+       from create_shortcuts_model().
+       (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+       to shortcuts_list.
+       (shortcuts_list_create): Renamed from shortcuts_tree_create().
+       (create_file_list): Enable the tree view as a model drag source.
+       (create_folder_tree): Likewise.
+
+       * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+       Register the drag source interface.
+       (drag_source_iface_init): New function.
+       (drag_source_row_draggable): New function.
+       (drag_source_drag_data_get): New function.
+
 Tue Feb 24 19:12:07 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.4 ===
index 1a13b2af34f9a290aab7bce925cba9e58cf932ad..13882efe842b98042ae9de657ab7e2dd788c3b16 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-24  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+       from create_shortcuts_model().
+       (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+       to shortcuts_list.
+       (shortcuts_list_create): Renamed from shortcuts_tree_create().
+       (create_file_list): Enable the tree view as a model drag source.
+       (create_folder_tree): Likewise.
+
+       * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+       Register the drag source interface.
+       (drag_source_iface_init): New function.
+       (drag_source_row_draggable): New function.
+       (drag_source_drag_data_get): New function.
+
 Tue Feb 24 19:12:07 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.4 ===
index 1a13b2af34f9a290aab7bce925cba9e58cf932ad..13882efe842b98042ae9de657ab7e2dd788c3b16 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-24  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+       from create_shortcuts_model().
+       (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+       to shortcuts_list.
+       (shortcuts_list_create): Renamed from shortcuts_tree_create().
+       (create_file_list): Enable the tree view as a model drag source.
+       (create_folder_tree): Likewise.
+
+       * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+       Register the drag source interface.
+       (drag_source_iface_init): New function.
+       (drag_source_row_draggable): New function.
+       (drag_source_drag_data_get): New function.
+
 Tue Feb 24 19:12:07 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.4 ===
index fc0a830c02b10430780e73ff1103d9d08beef6db..18b76c84ec17637a5b08f1769e3b8c094f20170a 100644 (file)
@@ -118,7 +118,7 @@ struct _GtkFileChooserDefault
   GtkWidget *tree_scrollwin;
   GtkWidget *tree;
   GtkWidget *shortcuts_scrollwin;
-  GtkWidget *shortcuts_tree;
+  GtkWidget *shortcuts_list;
   GtkWidget *add_bookmark_button;
   GtkWidget *remove_bookmark_button;
   GtkWidget *list_scrollwin;
@@ -159,7 +159,7 @@ enum {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-/* Column numbers for the shortcuts tree.  Keep these in sync with create_shortcuts_model() */
+/* Column numbers for the shortcuts tree.  Keep these in sync with shortcuts_model_create() */
 enum {
   SHORTCUTS_COL_PIXBUF,
   SHORTCUTS_COL_NAME,
@@ -620,7 +620,7 @@ shortcuts_unselect_all (GtkFileChooserDefault *impl)
 {
   GtkTreeSelection *selection;
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
   gtk_tree_selection_unselect_all (selection);
 }
 
@@ -958,7 +958,7 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
 }
 
 static void
-create_shortcuts_model (GtkFileChooserDefault *impl)
+shortcuts_model_create (GtkFileChooserDefault *impl)
 {
   if (impl->shortcuts_model)
     g_object_unref (impl->shortcuts_model);
@@ -979,7 +979,7 @@ create_shortcuts_model (GtkFileChooserDefault *impl)
       shortcuts_add_bookmarks (impl);
     }
 
-  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model));
+  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_list), GTK_TREE_MODEL (impl->shortcuts_model));
 }
 
 /* Callback used when the "New Folder" toolbar button is clicked */
@@ -1115,6 +1115,12 @@ create_folder_tree (GtkFileChooserDefault *impl)
   impl->tree = gtk_tree_view_new ();
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
 
+  gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->tree),
+                                         GDK_BUTTON1_MASK,
+                                         shortcuts_targets,
+                                         num_shortcuts_targets,
+                                         GDK_ACTION_COPY);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
   g_signal_connect (selection, "changed",
                    G_CALLBACK (tree_selection_changed), impl);
@@ -1292,7 +1298,7 @@ remove_bookmark_button_clicked_cb (GtkButton *button,
   gboolean removable;
   GError *error;
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
 
   if (gtk_tree_selection_get_selected (selection, NULL, &iter))
     {
@@ -1396,7 +1402,7 @@ bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
   GtkTreeIter iter;
   gboolean removable = FALSE;
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
 
   if (gtk_tree_selection_get_selected (selection, NULL, &iter))
     gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
@@ -1492,7 +1498,7 @@ shortcuts_selection_changed_cb (GtkTreeSelection      *selection,
 
 /* Creates the widgets for the shortcuts and bookmarks tree */
 static GtkWidget *
-shortcuts_tree_create (GtkFileChooserDefault *impl)
+shortcuts_list_create (GtkFileChooserDefault *impl)
 {
   GtkTreeSelection *selection;
   GtkTreeViewColumn *column;
@@ -1509,16 +1515,16 @@ shortcuts_tree_create (GtkFileChooserDefault *impl)
 
   /* Tree */
 
-  impl->shortcuts_tree = gtk_tree_view_new ();
-  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE);
+  impl->shortcuts_list = gtk_tree_view_new ();
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_list), FALSE);
   
-  gtk_drag_dest_set (impl->shortcuts_tree,
+  gtk_drag_dest_set (impl->shortcuts_list,
                     GTK_DEST_DEFAULT_ALL,
                     shortcuts_targets,
                     num_shortcuts_targets,
                     GDK_ACTION_COPY);
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
   gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
   gtk_tree_selection_set_select_function (selection,
                                          shortcuts_select_func,
@@ -1527,18 +1533,18 @@ shortcuts_tree_create (GtkFileChooserDefault *impl)
   g_signal_connect (selection, "changed",
                    G_CALLBACK (shortcuts_selection_changed_cb), impl);
 
-  g_signal_connect (impl->shortcuts_tree, "row-activated",
+  g_signal_connect (impl->shortcuts_list, "row-activated",
                    G_CALLBACK (shortcuts_row_activated_cb), impl);
 
-  g_signal_connect (impl->shortcuts_tree, "drag-data-received",
+  g_signal_connect (impl->shortcuts_list, "drag-data-received",
                    G_CALLBACK (shortcuts_drag_data_received_cb), impl);
 
-  gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_tree);
-  gtk_widget_show (impl->shortcuts_tree);
+  gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_list);
+  gtk_widget_show (impl->shortcuts_list);
 
   /* Model */
 
-  create_shortcuts_model (impl);
+  shortcuts_model_create (impl);
 
   /* Column */
 
@@ -1558,7 +1564,7 @@ shortcuts_tree_create (GtkFileChooserDefault *impl)
                                       "text", SHORTCUTS_COL_NAME,
                                       NULL);
 
-  gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_tree), column);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_list), column);
 
   return impl->shortcuts_scrollwin;
 }
@@ -1577,7 +1583,7 @@ shortcuts_pane_create (GtkFileChooserDefault *impl,
 
   /* Shortcuts tree */
 
-  widget = shortcuts_tree_create (impl);
+  widget = shortcuts_list_create (impl);
   gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
 
   /* Box for buttons */
@@ -1637,6 +1643,12 @@ create_file_list (GtkFileChooserDefault *impl)
                    G_CALLBACK (list_row_activated), impl);
   gtk_widget_show (impl->list);
 
+  gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->list),
+                                         GDK_BUTTON1_MASK,
+                                         shortcuts_targets,
+                                         num_shortcuts_targets,
+                                         GDK_ACTION_COPY);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
   g_signal_connect (selection, "changed",
                    G_CALLBACK (list_selection_changed), impl);
index a692bdf4195f18013cc6c266946c8551f3abd00f..d1575007dd5c698d6de72cb538b11f3a4e7f95f1 100644 (file)
@@ -23,6 +23,7 @@
 #include "gtkfilesystemmodel.h"
 #include "gtkfilesystem.h"
 #include "gtkintl.h"
+#include "gtktreednd.h"
 #include "gtktreemodel.h"
 
 typedef struct _GtkFileSystemModelClass GtkFileSystemModelClass;
@@ -91,6 +92,8 @@ static void gtk_file_system_model_iface_init   (GtkTreeModelIface       *iface);
 static void gtk_file_system_model_init         (GtkFileSystemModel      *model);
 static void gtk_file_system_model_finalize     (GObject                 *object);
 
+static void drag_source_iface_init (GtkTreeDragSourceIface *iface);
+
 static GtkTreeModelFlags gtk_file_system_model_get_flags       (GtkTreeModel *tree_model);
 static gint              gtk_file_system_model_get_n_columns   (GtkTreeModel *tree_model);
 static GType             gtk_file_system_model_get_column_type (GtkTreeModel *tree_model,
@@ -125,6 +128,12 @@ static void              gtk_file_system_model_ref_node        (GtkTreeModel *tr
 static void              gtk_file_system_model_unref_node      (GtkTreeModel *tree_model,
                                                                GtkTreeIter  *iter);
 
+static gboolean drag_source_row_draggable (GtkTreeDragSource   *drag_source,
+                                          GtkTreePath         *path);
+static gboolean drag_source_drag_data_get (GtkTreeDragSource   *drag_source,
+                                          GtkTreePath         *path,
+                                          GtkSelectionData    *selection_data);
+
 static FileModelNode *file_model_node_new        (GtkFileSystemModel *model,
                                                  const GtkFilePath  *path);
 static void           file_model_node_free       (FileModelNode      *node);
@@ -199,8 +208,15 @@ _gtk_file_system_model_get_type (void)
       static const GInterfaceInfo file_system_info =
       {
        (GInterfaceInitFunc) gtk_file_system_model_iface_init, /* interface_init */
-       NULL,                                                 /* interface_finalize */
-       NULL                                                  /* interface_data */
+       NULL,                                                  /* interface_finalize */
+       NULL                                                   /* interface_data */
+      };
+
+      static const GInterfaceInfo drag_source_info =
+      {
+       (GInterfaceInitFunc) drag_source_iface_init,           /* interface_init */
+       NULL,                                                  /* interface_finalize */
+       NULL                                                   /* interface_data */
       };
 
       file_system_model_type = g_type_register_static (G_TYPE_OBJECT,
@@ -209,6 +225,9 @@ _gtk_file_system_model_get_type (void)
       g_type_add_interface_static (file_system_model_type,
                                   GTK_TYPE_TREE_MODEL,
                                   &file_system_info);
+      g_type_add_interface_static (file_system_model_type,
+                                  GTK_TYPE_TREE_DRAG_SOURCE,
+                                  &drag_source_info);
     }
 
   return file_system_model_type;
@@ -277,6 +296,14 @@ gtk_file_system_model_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+drag_source_iface_init (GtkTreeDragSourceIface *iface)
+{
+  iface->row_draggable = drag_source_row_draggable;
+  iface->drag_data_get = drag_source_drag_data_get;
+  iface->drag_data_delete = NULL;
+}
+
 /*
  * ******************** GtkTreeModel methods ********************
  */
@@ -565,6 +592,60 @@ gtk_file_system_model_unref_node (GtkTreeModel *tree_model,
                         iter->user_data);
 }
 
+static gboolean
+drag_source_row_draggable (GtkTreeDragSource *drag_source,
+                          GtkTreePath       *path)
+{
+  GtkFileSystemModel *model;
+  GtkTreeIter iter;
+  FileModelNode *node;
+
+  model = GTK_FILE_SYSTEM_MODEL (drag_source);
+
+  if (!gtk_file_system_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
+    return FALSE;
+
+  if (!model->has_editable)
+    return TRUE;
+
+  node = iter.user_data;
+  return (node != model->roots);
+}
+
+static gboolean
+drag_source_drag_data_get (GtkTreeDragSource *drag_source,
+                          GtkTreePath       *path,
+                          GtkSelectionData  *selection_data)
+{
+  GtkFileSystemModel *model;
+  GtkTreeIter iter;
+  const GtkFilePath *file_path;
+  char *uri;
+  char *uris;
+
+  model = GTK_FILE_SYSTEM_MODEL (drag_source);
+
+  if (!gtk_file_system_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
+    return FALSE;
+
+  file_path = _gtk_file_system_model_get_path (model, &iter);
+  g_assert (file_path != NULL);
+
+  uri = gtk_file_system_path_to_uri (model->file_system, file_path);
+  uris = g_strconcat (uri, "\r\n", NULL);
+
+  gtk_selection_data_set (selection_data,
+                         gdk_atom_intern ("text/uri-list", FALSE),
+                         8,
+                         uris,
+                         strlen (uris) + 1);
+
+  g_free (uri);
+  g_free (uris);
+
+  return TRUE;
+}
+
 /**
  * _gtk_file_system_model_new:
  * @file_system: an object implementing #GtkFileSystem